from django.db import models
from datetime import datetime

# Create your models here.

class User(models.Model):
	class Meta:
		app_label = 'user'
		db_table = "user_account"
		verbose_name_plural = "所有用户"
		managed = False
		ordering = ["gmt_create"]

	GENDER_CATEGORY = (
		('male','男'),
		('female','女'),
	)

	ACCUNT_ACTIVE = (
		(0,"否",),
		(1,"是",),
	)

	id = models.PositiveIntegerField("用户id",primary_key=True)
	# has_user_name = models.PositiveSmallIntegerField("是否有用户名",blank=True,default=0)
	user_name = models.CharField("用户名",blank=True,max_length=20)
	password = models.CharField("密码",null=False,max_length=200)
	pet_name = models.CharField("昵称",blank=True,null=True,max_length=20)
	invitation_code = models.CharField("邀请码",blank=True,max_length=6)
	invite_amount = models.PositiveIntegerField("邀请好友数量",blank=True,default=0)
	salt = models.CharField("加密盐",null=True,max_length=50)
	last_login_time = models.DateTimeField("上次登陆时间",blank=True,default=datetime.now)
	is_actived = models.PositiveSmallIntegerField("账号是否激活",choices = ACCUNT_ACTIVE,blank=True)
	passivable_time = models.DateTimeField("激活／冻结时间",blank=True,null=True)
	is_deleted = models.PositiveSmallIntegerField("账号是否删除",blank=True)
	delete_time = models.DateTimeField("删除时间",blank=False,default=datetime.now)
	gmt_create = models.DateTimeField("账号注册时间",blank=True,default=datetime.now,null=True,)
	gmt_modified = models.DateTimeField("修改时间",blank=True,default=datetime.now,null=True,)
	gender = models.CharField("性别", choices = GENDER_CATEGORY, blank=True, null=True,max_length=10,default='male')
	def __str__(self):
		return str(self.id)

class UserQq(models.Model):
	class Meta:
		db_table = "user_bind_qq"
		verbose_name_plural = "QQ"
		managed = False
	id = models.OneToOneField(User,db_column='id',primary_key=True,related_name='userqq',unique=True)
	union_id = models.CharField("QQ union_id",max_length=50,unique=True)
	def __str__(self):
		return str(self.union_id)

class UserWechat(models.Model):
	class Meta:
		db_table = "user_bind_wechat"
		verbose_name_plural = "微信"
		managed = False
	id = models.OneToOneField(User,db_column='id',primary_key=True,related_name='userwechat',unique=True)
	union_id = models.CharField("微信 union_id",max_length=50,unique=True,)
	def __str__(self):
		return str(self.union_id)


class UserMobile(models.Model):
	class Meta:
		db_table = "user_bind_mobile"
		verbose_name_plural = "手机"
		managed = False
	id = models.OneToOneField(User,db_column='id',primary_key=True,related_name='usermobile',unique=True)
	mobile = models.CharField("手机号",max_length=20,unique=True)
	def __str__(self):
		return self.mobile
